package ${packageName};

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.content.ContextCompat;

import ${applicationPackage}.BR;
import ${applicationPackage}.R;
import ${applicationPackage}.databinding.${underscoreToCamelCase(layoutName)}Binding;
<#if generateFragment>
import ${packageName}.fragment.${fragmentName};
</#if>
<#if generateViewModel>
import ${packageName}.viewModel.${viewModelName};
</#if>

import java.util.ArrayList;
import java.util.List;

import me.majiajie.pagerbottomtabstrip.NavigationController;
import me.majiajie.pagerbottomtabstrip.listener.OnTabItemSelectedListener;
import me.goldze.mvvmhabit.base.BaseActivity;
<#if !generateViewModel>
import me.goldze.mvvmhabit.base.BaseViewModel;
</#if>

/**
 * //底部tabBar 需要在build.gradle导入
 * implementation('me.majiajie:pager-bottom-tab-strip:2.2.5'){
 * exclude group:'com.android.support'
 * }
 * <p>
 * ${activityLabel}
 */
public class ${activityClass} extends BaseActivity<${underscoreToCamelCase(layoutName)}Binding,<#if generateViewModel>${viewModelName}<#else>BaseViewModel</#if> > {
	private List<Fragment> mFragments;   
    
	@Override
    public int initContentView(Bundle savedInstanceState) {
        return R.layout.${layoutName};
    }

    @Override
    public int initVariableId() {
        return BR.viewModel;
    }

//    @Override
//    public ${viewModelName} initViewModel() {
//        //View持有ViewModel的引用，如果没有特殊业务处理，这个方法可以不重写
//        return ViewModelProviders.of(this).get(${viewModelName}.class);
//    }
    @Override
    public void initViewObservable() {


    }

	 @Override
    public void initData() {
        //初始化Fragment
        initFragment();
        //初始化底部Button
        initBottomTab();
    }

    private void initFragment() {
        mFragments = new ArrayList<>();
        mFragments.add(new ${fragmentName}());
        mFragments.add(new ${fragmentName}());
        mFragments.add(new ${fragmentName}());
        mFragments.add(new ${fragmentName}());
        //默认选中第一个
        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
        transaction.add(R.id.frameLayout, mFragments.get(0));
        transaction.commitAllowingStateLoss();
    }

    private void initBottomTab() {
        NavigationController navigationController = binding.pagerBottomTab.material()
                .addItem(R.mipmap.ic_launcher, "应用")
                .addItem(R.mipmap.ic_launcher, "工作")
                .addItem(R.mipmap.ic_launcher, "消息")
                .addItem(R.mipmap.ic_launcher, "我的")
                .setDefaultColor(ContextCompat.getColor(this, R.color.colorAccent))
                .build();
        //底部按钮的点击事件监听
        navigationController.addTabItemSelectedListener(new OnTabItemSelectedListener() {
            @Override
            public void onSelected(int index, int old) {
                FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
                transaction.replace(R.id.frameLayout, mFragments.get(index));
                transaction.commitAllowingStateLoss();
            }

            @Override
            public void onRepeat(int index) {
            }
        });
    }
}
